<?php

class Nn_model extends CI_Model
{
	private $DB, $Mytile;

	public function __construct()
	{
		parent::__construct();
		$this->DB = $this->load->database('admin', TRUE);
	}
	/**
	 * 读取最新文章列表
	 */
	public function read_new_news_mysql($page, $rows)
	{
		$this->DB->reconnect();
		//检查数据库是否存在此用户名
		$query = $this->DB->query("SELECT * FROM news  ORDER BY time DESC LIMIT $page,$rows ;");
		$newslist = array();
		if ($this->DB->affected_rows() == 0) {
			return null;
		}
		foreach ($query->result_array() as $row) {
			$newslist[] = $row;
		}
		return $newslist;
	}
	/**
	 * 读取文章一共的数量
	 * $name 传入的表名称
	 */
	public function news_count($name)
	{
		$this->DB->reconnect();
		//检查数据库是否存在此用户名
		$query = $this->DB->query("SELECT  COUNT(*) FROM $name;");
		$row = $query->row_array();
		$count = $row['COUNT(*)'];
		return $count;
	}

}
